package com.example.tool.adapter.base.decoration;

import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created Date 2019/12/4.
 *
 * @author liangkun
 * ClassDescription：
 */
public class GrideDecoration extends RecyclerView.ItemDecoration {
    private int spacing;
    private int top;

    public GrideDecoration(int top, int spacing) {
        this.spacing = spacing;
        this.top = top;
    }


    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.top = top;
        outRect.bottom = 0;
// top bottom left right 对应的值应该是dpi 而不是dp  dpi根据不同手机而不同

        int i = parent.getChildLayoutPosition(view) % 3;//每行3个
        //方案1
        switch (i) {
            case 0://第一个
                outRect.left = spacing*2;
                outRect.right = 0;
                break;
            case 1://第二个
                outRect.left = spacing;
                outRect.right = 0;
                break;
            case 2://第三个
                outRect.left = spacing;
                outRect.right = spacing*2;
                break;
        }

    }

}
